<?php

namespace addons\shopro\controller\wm;

use addons\shopro\exception\Exception;
use think\Db;
use addons\shopro\controller\Base as AddonsBase;
class Money extends AddonsBase
{

    protected $noNeedLogin = [''];
    protected $noNeedRight = ['*'];


    /**
     * 团长。商家 个人中心 资金统计
     * 王猛 2022-1-25 14:14:07
     */
    function getMoney(){
        if ($this->request->isPost()) {
            $user_id = $this->auth->id;
            $types = $this->request->param('types');
            $store_id = $this->request->param('store_id');
            if(!in_array($types,['sj','pt','xt'])) $this->error('系统开了个小差！');
//        $types= $types??'xt';
            //累计佣金
            if(!empty($store_id)){
                $map['store_id'] = array('=',$store_id);
                $map1['store_id'] = array('=',$store_id);
            }

            $map['wm_types'] = array('=',$types);
            $map['user_id'] = array('=',$user_id);


            $map1['wm_types'] = array('=',$types);
            $map1['user_id'] = array('=',$user_id);
            $map1['is_refund'] = array('=',1);
            $map1['wallet'] = array('<',0);


            $money_can_get = db('shopro_user_wallet_log')
                ->where(function ($query) use ($map) {
                    $query->where($map);
                })
                ->whereOr(function ($query) use ($map1) {
                    $query->where($map1);
                })
                ->sum('wallet');

            $map['wallet'] = array('>',0);
            $map['type'] = array('<>','cash_error');
            $money_all = db('shopro_user_wallet_log')
                ->where(function ($query) use ($map) {
                    $query->where($map);
                })
                ->whereOr(function ($query) use ($map1) {
                    $query->where($map1);
                })
                ->sum('wallet');


            $data = [
                'money_all'=>round($money_all,2),
//                'money_has_get'=>round($money_get,2),
                'money_can_get'=> round($money_can_get,2),
            ];
            $this->success('',$data);
        }

    }



}